//-----------------------------------------------------------------------------
// File: AbscissaScroller.cs
//
// Copyright (c) Dmitry Shuklin. All rights reserved.
//-----------------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Direct3D = Microsoft.DirectX.Direct3D;

namespace ObjectiveDraw.Platform
{
	public class AbscissaScroller : Cerebrum.Direct3D.Forms.Control 
	{
		private System.ComponentModel.IContainer components = null;

		public AbscissaScroller()
		{
			// This call is required by the Windows Form Designer.
			InitializeComponent();

			// TODO: Add any initialization after the InitializeComponent call
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			components = new System.ComponentModel.Container();
		}
		#endregion

		protected override void OnRenderScene(Cerebrum.Direct3D.Forms.RenderEventArgs e)
		{
				RectangleF rullrect = e.ClipRectangle;
				Cerebrum.Direct3D.Drawing.Graphics g = Cerebrum.Direct3D.Drawing.Graphics.FromDevice(e.Device);

				GraphChartDevice dev = this.Parent as GraphChartDevice;
				object rullback = dev.RulerHorizontalBackColor;

				if(rullback is System.Drawing.Color)
				{
					System.Drawing.Color rullbackc = (System.Drawing.Color)rullback;
					System.Drawing.RectangleF devrect = dev.SurfaceRectangle;

					Texture _ImageTexture = Cerebrum.Direct3D.Drawing.Graphics.DeviceObjects[e.Device, GraphChartDevice.GraphBackgroundImageKey] as Texture;


					if(_ImageTexture == null)
					{
						if(rullbackc.A > 0)
						{
							g.DrawRectangle(rullrect, Z, rullbackc, true);
						}
					}
					else
					{
						g.DrawRectangle(rullrect, Z, _ImageTexture, new RectangleF(rullrect.X / devrect.Width, rullrect.Y / devrect.Height, rullrect.Width / devrect.Width, rullrect.Height / devrect.Height), rullbackc);
					}
				}


				DrawerBarDrawHelper.DrawHRuller(e.Device, rullrect, DrawingFont, AbscissaPosition, 16, Z, true, this.FindDevice() as GraphChartDevice);


				int borderH = dev.RulerHorizontalBorderInteger;
				if(borderH>0)
				{
					System.Drawing.RectangleF _rect = System.Drawing.RectangleF.Empty;

					_rect = new RectangleF(rullrect.X - 0.5f, rullrect.Y - 0.5f, rullrect.Width/* - dev.m_OrdinateRullerWidth*/, borderH);

					Color borderC = dev.RulerHorizontalBorderColor;

					g.DrawRectangle(_rect, Z, borderC, true);
				}

				/*if(timeBase!=null)
					DrawerBarDrawHelper.DrawHTimes(e.Device, DrawingFont, AbscissaPosition, (this.Parent as GraphChartDevice).BeginDateTime, timeBase.Stride, 16, 0.4f, true, Color.LightBlue);*/
			

			base.OnRenderScene (e);
		}
	
		public Cerebrum.Direct3D.Drawing.Font DrawingFont = null;

		public CoordinatePosition AbscissaPosition = null;
	}
}

